﻿using System;
using System.Collections.Generic;
using System.Text;
using Enterprise;

namespace Enterprise.Modules
{
    /// <summary>
    /// Base class for all modules. Encapsulates the general module properties and methods.
    /// </summary>
    /// <typeparam name="T">Type of the module-data class (this type is just passed to DataManager)
    public abstract class Module<T> : DataManager<T>, IModule
    {
        private string _moduleId;

        /// <summary>
        /// Creates a new module with a new Module id
        /// </summary>
        public Module() : base()
        {
            _moduleId = Config.CreateID();
        }

        /// <summary>
        /// Creates a module with the given Module id.
        /// </summary>
        /// <param name="id">Guid of the module</param>
        public Module(string id)
        {
            _moduleId = id;
            LoadData();
        }

        /// <summary>
        /// The unique module identifier (id)
        /// </summary>
        public string ModuleId
        {
            get { return _moduleId.ToString(); }
        }

        /// <summary>
        /// Returns a virtual path to the module's UserControl that is used to display the module in the WebPage
        /// The path is a virtual path to an assembly and it's UserControl in it.
        /// </summary>
        public string UserControl
        {
            //The trailing /is used to call Provider
            get { return string.Format("/App_Resource/Enterprise.{0}.dll/Enterprise.Modules.{0}.ascx", GetType().Name); }
        }

        /// <summary>
        /// Path to the datafile.
        /// </summary>
        /// <returns>The path to the data-file of the current module</returns>
        protected override string GetID()
        {
            return _moduleId;
        }

        //Tells if a module is active
        public abstract bool Active { get; set; }

        //If RewritePrefix has a value, this is the prefix to look for in url
        //If RewritePrefix is null, it doesn't has any rewrite.
        public abstract string RewritePrefix { get; }


    }
}
